#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define eps 1e-8
inline int dcmp(double x) {
    return (x<-eps)?-1:(x>eps);
}
struct Point {
    double x,y;
    Point() {}
    Point(double x,double y):x(x),y(y) {}
    void in() {
        scanf("%lf%lf",&x,&y);
    }
    Point operator +(const Point& a)const {
        return Point(x+a.x,y+a.y);
    }
    Point operator -(const Point& a)const {
        return Point(x-a.x,y-a.y);
    }
    Point operator *(const double& k)const {
        return Point(x*k,y*k);
    }
    double operator*(const Point& a)const {
        return x*a.x+y*a.y;
    }
    double operator^(const Point& a)const {
        return x*a.y-a.x*y;
    }
    double X(Point a,Point b) {
        return a-*this^b-*this;
    }
};
int n;
const int N=511;
const int maxsz=4;
struct poly {
    int sz;//边数
    Point p[maxsz+1];
    void in() {
        //scanf("%d",&sz);
        for(int i=0; i<sz; i++) p[i].in();
        p[sz]=p[0];
    }
    void anti() {
        if(dcmp(p[0].X(p[1],p[2])<0)) reverse(p,p+sz);
        p[sz]=p[0];
    }
    double S() {
        double s=0;

        for(int i=0; i<sz; i++) s+=p[i]^p[i+1];
        return s*0.5;
    }
} ply[N];
pair<double,int> E[N*200];
inline double ratio(Point a,Point b,Point p) {
    if(dcmp( b.x-a.x )) return (p.x-a.x)/(b.x-a.x);
    return (p.y-a.y)/(b.y-a.y);
}
double US(poly *ply,int n) {
    double s=0;
    for(int i=0; i<n; i++)
        for(int x=0; x<ply[i].sz; x++) {
            int cnt=0;
            E[cnt++]=make_pair(0.0,0);
            E[cnt++]=make_pair(1.0,0);
            for(int j=0; j<n; j++) {
                if(i==j) continue;
                for(int y=0; y<ply[j].sz; y++) {
                    int dir1=dcmp( ply[i].p[x].X(ply[i].p[x+1],ply[j
                    ].p[y]) );
                    int dir2=dcmp( ply[i].p[x].X(ply[i].p[x+1],ply[j
                    ].p[y+1]) );
                    if(!dir1 && !dir2) {
                        if(i>j && (ply[i].p[x+1]-ply[i].p[x])*(ply[j
                                                               ].p[y+1]-ply[j].p[y])>0) {
                            E[cnt++]=make_pair(ratio(ply[i].p[x],ply
                            [i].p[x+1],ply[j].p[y]),1);
                            E[cnt++]=make_pair(ratio(ply[i].p[x],ply
                            [i].p[x+1],ply[j].p[y+1]),-1);
                        }
                    } else if(dir1>=0 && dir2<0) {
                        double s1=ply[j].p[y].X(ply[j].p[y+1],ply[i]
                                .p[x]);
                        double s2=ply[j].p[y].X(ply[j].p[y+1],ply[i]
                                .p[x+1]);
                        E[cnt++]=make_pair(s1/(s1-s2),1);
                    } else if(dir1<0 && dir2>=0) {
                        double s1=ply[j].p[y].X(ply[j].p[y+1],ply[i]
                                .p[x]);
                        double s2=ply[j].p[y].X(ply[j].p[y+1],ply[i]
                                .p[x+1]);
                        E[cnt++]=make_pair(s1/(s1-s2),-1);
                    }
                }
            }
            sort(E,E+cnt);
            double last=min(max(E[0].first,0.0),1.0),r=0.0,cur;
            int L=E[0].second;
            for(int k=1; k<cnt; k++) { /*cur and last is unnecessary
n个凸多边形⾯积并
3/37
n个凸多边形⾯积交
！*/
                cur=min(max(E[k].first,0.0),1.0);
                if(!L) r+=cur-last;
                L+=E[k].second;
                last=cur;
            }
            s+=(ply[i].p[x]^(ply[i].p[x+1]))*r;
        }
    return s*0.5;
}
int main() {
    n=2;
    int t;
    scanf("%d",&t);
    while(t--) {
        ply[0].sz=3;
        ply[1].sz=4;
        for(int i=0; i<n; i++) {
            ply[i].in();
            ply[i].anti(); //规整化
        }
        printf("%.9f\n",US(ply,n));
    }
    return 0;
}